package cn.edu.cug.cs.gtl.apis.ui.datake.catalogtree;

import cn.edu.cug.cs.gtl.apis.ui.AbstractApplication;
import cn.edu.cug.cs.gtl.apis.ui.tree.Tree;

import javax.swing.*;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreeNode;
import java.util.Hashtable;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.Vector;

/**
 * Created by ZhenwenHe on 2016/12/6.)
 * 1) 确定节点种类（CatalogNode\GroupNode\ItemNode）
 * 2）确定每种节点的弹出菜单；
 * 3）新建一个插件工程(catalog-plugin)，用于管理数据目录树，包括节点的增删改查，节点的移动，节点的复制粘贴，节点的显示隐藏，节点的排序，节点的保存等
 * 4) 插件工程(catalog-plugin)中实现各个菜单功能
 */
public class CatalogTree extends Tree {

    private static JPopupMenu treePopupMenu = new JPopupMenu();
    private static JPopupMenu catalogNodePopupMenu = new JPopupMenu();
    private static JPopupMenu groupNodePopupMenu = new JPopupMenu();
    private static JPopupMenu itemNodePopupMenu = new JPopupMenu();

    /**
     * Returns a <code>JTree</code> with a sample model.
     * The default model used by the tree defines a leaf node as any node
     * without children.
     */
    public CatalogTree() {
    }

    /**
     * Returns a <code>JTree</code> with each element of the
     * specified array as the
     * child of a new root node which is not displayed.
     * By default, the tree defines a leaf node as any node without
     * children.
     *
     * @param value an array of <code>Object</code>s
     */
    public CatalogTree(Object[] value) {
        super(value);
    }

    /**
     * Returns a <code>JTree</code> with each element of the specified
     * <code>Vector</code> as the
     * child of a new root node which is not displayed. By default, the
     * tree defines a leaf node as any node without children.
     *
     * @param value a <code>Vector</code>
     */
    public CatalogTree(Vector<?> value) {
        super(value);
    }

    /**
     * Returns a <code>JTree</code> created from a <code>Hashtable</code>
     * which does not display with root.
     * Each value-half of the key/value pairs in the <code>HashTable</code>
     * becomes a child of the new root node. By default, the tree defines
     * a leaf node as any node without children.
     *
     * @param value a <code>Hashtable</code>
     */
    public CatalogTree(Hashtable<?, ?> value) {
        super(value);
    }

    /**
     * Returns a <code>JTree</code> with the specified
     * <code>TreeNode</code> as its root,
     * which displays the root node.
     * By default, the tree defines a leaf node as any node without children.
     *
     * @param root a <code>TreeNode</code> object
     */
    public CatalogTree(TreeNode root) {
        super(root);
    }

    /**
     * Returns a <code>JTree</code> with the specified <code>TreeNode</code>
     * as its root, which
     * displays the root node and which decides whether a node is a
     * leaf node in the specified manner.
     *
     * @param root               a <code>TreeNode</code> object
     * @param asksAllowsChildren if false, any node without children is a
     *                           leaf node; if true, only nodes that do not allow
     *                           children are leaf nodes
     */
    public CatalogTree(TreeNode root, boolean asksAllowsChildren) {
        super(root, asksAllowsChildren);
    }

    /**
     * Returns an instance of <code>JTree</code> which displays the root node
     * -- the tree is created using the specified data model.
     *
     * @param newModel the <code>TreeModel</code> to use as the data model
     */
    public CatalogTree(TreeModel newModel) {
        super(newModel);
    }

    public JPopupMenu getTreePopupMenu() {
        return treePopupMenu;
    }

    public void setTreePopupMenu(JPopupMenu treePopupMenu) {
        this.treePopupMenu = treePopupMenu;
    }

    public JPopupMenu getCatalogNodePopupMenu() {
        return catalogNodePopupMenu;
    }

    public void setCatalogNodePopupMenu(JPopupMenu catalogNodePopupMenu) {
        this.catalogNodePopupMenu = catalogNodePopupMenu;
    }

    public JPopupMenu getGroupNodePopupMenu() {
        return groupNodePopupMenu;
    }

    public void setGroupNodePopupMenu(JPopupMenu groupNodePopupMenu) {
        this.groupNodePopupMenu = groupNodePopupMenu;
    }

    public JPopupMenu getItemNodePopupMenu() {
        return itemNodePopupMenu;
    }

    public void setItemNodePopupMenu(JPopupMenu itemNodePopupMenu) {
        this.itemNodePopupMenu = itemNodePopupMenu;
    }

    //创建默认情况下的右键菜单
    public static JPopupMenu createDefaultPopupMenuForTree() {
//        ResourceBundle resourceBundle = ResourceBundle.getBundle("uiapi_resource", Locale.getDefault());
//        JPopupMenu popupMenu = new JPopupMenu();
//        JMenuItem menuItem = new JMenuItem("add data catalog");
//        treePopupMenu.add(menuItem);
//        popupMenu.add(menuItem);
        return treePopupMenu;
    }

    //创建鼠标在CatalogNode上的右键菜单
    public static JPopupMenu createDefaultPopupMenuForCatalogNode() {
//        ResourceBundle resourceBundle = ResourceBundle.getBundle("uiapi_resource", Locale.getDefault());
//        resourceBundle.getString();
//        JPopupMenu popupMenu = new JPopupMenu();
//        popupMenu.add(new JMenuItem(""));
        return catalogNodePopupMenu;
    }

    //创建鼠标在GroupNode上的右键菜单
    public static JPopupMenu createDefaultPopupMenuForGroupNode() {
//        ResourceBundle resourceBundle = ResourceBundle.getBundle("uiapi_resource", Locale.getDefault());
//        JPopupMenu popupMenu = new JPopupMenu();
        return groupNodePopupMenu;
    }

    //创建鼠标在ItemNode上的右键菜单
    public static JPopupMenu createDefaultPopupMenuForItemNode() {
//        ResourceBundle resourceBundle = ResourceBundle.getBundle("uiapi_resource", Locale.getDefault());
//        JPopupMenu popupMenu = new JPopupMenu();
        return itemNodePopupMenu;
    }
}
